"use strict";
function changeTextureName(t) {
	swal({
		text: trans("skinlib.setNewTextureName"),
		input: "text",
		showCancelButton: !0,
		inputValidator: function(t) {
			return new Promise(function(e, n) {
				t ? e() : n(trans("skinlib.emptyNewTextureName"))
			})
		}
	}).then(function(e) {
		$.ajax({
			type: "POST",
			url: url("skinlib/rename"),
			dataType: "json",
			data: {
				tid: t,
				new_name: e
			},
			success: function(t) {
				0 == t.errno ? ($("#name").text(e), toastr.success(t.msg)) : toastr.warning(t.msg)
			},
			error: showAjaxError
		})
	})
}

function changePrivacy(t) {
	$.ajax({
		type: "POST",
		url: url("skinlib/privacy"),
		dataType: "json",
		data: {
			tid: t
		},
		success: function(t) {
			0 == t.errno ? (toastr.success(t.msg), "0" == t["public"] ? $('a:contains("' + trans("skinlib.setAsPrivate") + '")').html(trans("skinlib.setAsPublic")) : $('a:contains("' + trans("skinlib.setAsPublic") + '")').html(trans("skinlib.setAsPrivate"))) : toastr.warning(t.msg)
		},
		error: showAjaxError
	})
}

function deleteTexture(t) {
	swal({
		text: trans("skinlib.deleteNotice"),
		type: "warning",
		showCancelButton: !0
	}).then(function() {
		$.ajax({
			type: "POST",
			url: url("skinlib/delete"),
			dataType: "json",
			data: {
				tid: t
			},
			success: function(t) {
				0 == t.errno ? swal({
					type: "success",
					html: t.msg
				}).then(function() {
					return window.location = url("skinlib")
				}) : swal({
					type: "warning",
					html: t.msg
				})
			},
			error: showAjaxError
		})
	})
}
$(document).ready(function() {
	return swal.setDefaults({
		confirmButtonText: trans("general.confirm"),
		cancelButtonText: trans("general.cancel")
	})
}), $("#page-select").on("change", function() {
	var t = getQueryString("sort"),
		e = getQueryString("page"),
		n = getQueryString("filter"),
		a = $(this).val();
	n || t ? null == e ? window.location = location.href + "&page=" + a : window.location = "?filter=" + n + "&sort=" + t + "&page=" + a : window.location = "?page=" + a
}), $("#private").on("ifToggled", function() {
	$(this).prop("checked") ? $("#msg").show() : $("#msg").hide()
}), $("#type-skin").on("ifToggled", function() {
	$(this).prop("checked") ? $("#skin-type").show() : $("#skin-type").hide()
}), $("body").on("change", "#file", function() {
	return handleFiles()
}).on("ifToggled", "#type-cape", function() {
	MSP.clear(), handleFiles()
}), $(".private-label").click(function() {
	var t = this;
	swal({
		text: trans("skinlib.setPublicNotice"),
		type: "warning",
		showCancelButton: !0
	}).then(function() {
		changePrivacy($(t).attr("tid")), $(t).remove()
	})
});

